﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Runtime.Remoting.Contexts;
namespace SRAGWMCLib
{
    /// <summary>
    /// Singleton that allow the MapServer to be created only once, 
    /// and thus, be saved for multiple uses
    /// </summary>
    /// 

    public class SRAMapServerBuilder
    {
        private static bool _check;
        private static object _map;
        
        /// <summary>
        /// Checks if the MapServer is already running or not, if not it returns his last instance
        /// </summary>
        /// <returns>Returns the .Com object to the object that keeps the MapServer (objMapServerBuilder)</returns>
        /// 

        public static object GetMap()
        {
            if (_check == false)
            {
                _map = CreateObject();
                _check = true;
            }
            return _map;
        }

        /// <summary>
        /// Creates the MapServer
        /// </summary>
        /// <returns>Returns the .Com object to the object that keeps the MapServer (objMapServerBuilder)</returns>
        /// 

        private static object CreateObject()
        {
            MapSvrMngrLib.MapServerManager objSesMgr = (MapSvrMngrLib.MapServerManager)HttpContext.Current.Server.CreateObject("GMWebMap.MapServerManager");
            return objSesMgr.MapServer("");
        }
    }
}
